home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / emul / cp4 / c2p_src / c2p_module.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  9KB  |  310 lines

  1. /* :ts=4                            c2p_module.c
  2.  *
  3.  *    cp4 - Commodore C+4 emulator
  4.  *    Copyright (C) 1998 Gáti Gergely
  5.  *
  6.  *    This program is free software; you can redistribute it and/or modify
  7.  *    it under the terms of the GNU General Public License as published by
  8.  *    the Free Software Foundation; either version 2 of the License, or
  9.  *    (at your option) any later version.
  10.  *
  11.  *    This program is distributed in the hope that it will be useful,
  12.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *    GNU General Public License for more details.
  15.  *
  16.  *    You should have received a copy of the GNU General Public License
  17.  *    along with this program; if not, write to the Free Software Foundation,
  18.  *    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  *
  20.  *    e-mail: gatig@dragon.klte.hu
  21.  */
  22. #ifndef C2P_MODULE_C
  23. #define C2P_MODULE_C
  24.  
  25. #ifndef C2P_MODULE_H
  26.  #include "c2p_module.h"
  27. #endif
  28.  
  29. #ifdef C2P_LOCALIZE
  30.  
  31.  #ifdef C2P_INFO
  32.   #error If you define C2P_LOCALIZE, you must use minfo() instead of C2P_INFO.
  33.  #endif
  34.  
  35.  #ifndef C2P_WANTSYSBASE
  36.   #define C2P_WANTSYSBASE
  37.  #endif
  38.  
  39.  #define C2P_CATALOGNAME    "cp4_" ## C2P_NAME ## ".catalog"
  40.  
  41.  #ifndef C2P_BUILTINLANGUAGE
  42.   #define C2P_BUILTINLANGUAGE    "english"
  43.  #endif
  44.  
  45.  #include <libraries/locale.h>
  46.  #include <proto/locale.h>
  47.  #include <proto/intuition.h>
  48.  
  49.  void c2p_OpenCatalog(char **DefaultStrings);
  50.  char *c2p_GetStr(long StringNum);
  51.  void c2p_CloseCatalog(void);
  52.  
  53.  #define STR(n) c2p_GetStr(n)
  54.  
  55.  extern struct IntuitionBase *IntuitionBase;
  56.  
  57.  struct LocaleBase *LocaleBase;
  58.  struct Catalog *c2p_Catalog=0L;
  59.  static int c2p_NumberOfMessages=0;
  60.  static char **c2p_DefaultStrings=0L;
  61.  
  62. #endif        // C2P_LOCALIZE
  63.  
  64. #ifdef C2P_INFO
  65.  #warning C2P_INFO is obsolote, use minfo() instead.
  66. #endif
  67.  
  68. #ifdef C2P_WANTSYSBASE
  69.  #include <exec/types.h>
  70.  #include <proto/exec.h>
  71. #else
  72.  #warning You have to define SysBase yourself.
  73. #endif
  74.  
  75. #include "macros.h"
  76.  
  77. #define SCRWIDTH    352
  78. #define SCRHEIGHT    283
  79. #define SCRSIZE        (SCRWIDTH*SCRHEIGHT)
  80. #define NUMSCR        3
  81. #define C2P_NOMSG    "\0"
  82. #define C2P_NOMEM    "Not Enough Memory"
  83. #define RET_ERROR    -2
  84. #define RET_NEWWIN    -1
  85. #define RET_OK        0
  86. #define RET_DEBUG    1
  87. #define RET_PREFS    2
  88. #define RET_RESET    3
  89. #define RET_HRESET    4
  90. #define RET_QUIT    5
  91.  
  92. char *SAVEDS minit(ULONG scrmode, ULONG overscan, unsigned char *linedeltatab);
  93. void SAVEDS mfree(void);
  94. int SAVEDS mdo(unsigned char *chunky,unsigned char *delta,int numscreen);
  95. int SAVEDS mdofull(unsigned char *chunky,int numscreen);
  96. int SAVEDS mdont(void);
  97. void SAVEDS msleep(void);
  98. void SAVEDS mawake(void);
  99. #ifndef C2P_INFO
  100.  char *SAVEDS minfo(void);
  101. #endif
  102.  
  103. static char *SAVEDS iinit(ULONG sm, ULONG ov, unsigned char *ld);
  104. static int SAVEDS idofull(unsigned char *chunky,unsigned char *delta,int numscreen);
  105.  
  106. static int DummyGetOptionInt(char *name,int defval);
  107. static void DummyAddOptionInt(char *name,int value);
  108. static char *DummyGetOptionStr(char *name,char *defval);
  109. static void DummyAddOptionStr(char *name,char *value);
  110.  
  111. static int SAVEDS c2p_internal(int);
  112.  
  113. static struct c2pvec vec;
  114.  
  115. static ULONG c2p_sm;
  116. static ULONG c2p_ov;
  117. static unsigned char *c2p_ld;
  118.  
  119. #ifdef C2P_WANTSYSBASE
  120.  struct ExecBase *SysBase;
  121. #endif
  122.  
  123. #ifndef C2P_AUTHOR
  124.  #define C2PI_COPYRIGHT    ""
  125.  #warning C2P_AUTHOR is not defined.
  126. #else
  127.  #define C2PI_COPYRIGHT    " Copyright © by " ## C2P_AUTHOR
  128. #endif
  129.  
  130. #ifdef __SASC
  131.  #define C2P_VERSTAG "\0$VER: " ## C2P_NAME ## " " ## C2P_VERSION ## "." ## C2P_REVISION ## " " ## __AMIGADATE__ ## C2PI_COPYRIGHT
  132. #else
  133.  #ifndef C2P_DATE
  134.   #define C2P_VERSTAG "\0$VER: " ## C2P_NAME ## " " ## C2P_VERSION ## "." ## C2P_REVISION ## " (" ## __DATE__ ## ")" ## C2PI_COPYRIGHT
  135.  #else
  136.   #define C2P_VERSTAG "\0$VER: " ## C2P_NAME ## " " ## C2P_VERSION ## "." ## C2P_REVISION ## " (" ## C2P_DATE ## ")" ## C2PI_COPYRIGHT
  137.  #endif        // C2P_DATE
  138. #endif        // __SASC
  139. static char c2p_VersTag[]=C2P_VERSTAG;
  140.  
  141. struct c2pvec REGARGS SAVEDS *startup(REG(d0,unsigned long m)) {
  142. static char iVer[]=C2P_VERSION;
  143. static char iRev[]=C2P_REVISION;
  144. static char iNam[]=C2P_NAME;
  145. #ifdef C2P_AUTHOR
  146.  static char iAut[]=C2P_AUTHOR;
  147. #else
  148.  static char iAut[]="???";
  149. #endif
  150. #ifdef C2P_INFO
  151.  static char iInf[]=C2P_INFO;
  152. #else
  153.  static char *iInf=NULL;
  154. #endif
  155.  
  156.     if(m!=C2P_MAGIC) return((struct c2pvec *)-1);
  157. #ifdef C2P_WANTSYSBASE
  158.     SysBase=*((struct ExecBase **)4L);
  159. #endif
  160. #ifndef C2P_INFO
  161.     if(iInf==NULL) iInf=minfo();
  162. #endif
  163.     vec.c2p_init=iinit;
  164.     vec.c2p_free=mfree;
  165.     vec.c2p_do=mdo;
  166.     vec.c2p_dofull=idofull;
  167.     vec.c2p_sleep=msleep;
  168.     vec.c2p_awake=mawake;
  169.     vec.c2p_Info=iInf;
  170.     vec.c2p_Author=iAut;
  171.     vec.c2p_Version=iVer;
  172.     vec.c2p_Revision=iRev;
  173.     vec.c2p_Name=iNam;
  174.     vec.c2p_Scr=NULL;
  175.     vec.c2p_Win=NULL;
  176.     vec.c2p_GetOptionInt=DummyGetOptionInt;
  177.     vec.c2p_AddOptionInt=DummyAddOptionInt;
  178.     vec.c2p_GetOptionStr=DummyGetOptionStr;
  179.     vec.c2p_AddOptionStr=DummyAddOptionStr;
  180.     vec.c2p_MsgList.lh_Head=(struct Node *)&vec.c2p_MsgList.lh_Tail;
  181.     vec.c2p_MsgList.lh_Tail=NULL;
  182.     vec.c2p_MsgList.lh_TailPred=(struct Node *)&vec.c2p_MsgList.lh_Head;
  183.     vec.c2p_MsgList.lh_Type=0;
  184. #ifdef C2P_BUFFERING
  185.     vec.c2p_Buffering=C2P_BUFFERING;
  186.     if(vec.c2p_Buffering<0||vec.c2p_Buffering>3) vec.c2p_Buffering=0;
  187. #else
  188.     vec.c2p_Buffering=0;
  189. #endif
  190.     vec.c2p_Speed=-1;
  191. #ifdef C2P_NOSPEED
  192.     vec.c2p_NoSpeed=1;
  193. #else
  194.     vec.c2p_NoSpeed=0;
  195. #endif
  196.     c2p_VersTag[0]='\0';
  197.     vec.c2p_dont=mdont;
  198.     vec.c2p_internal=c2p_internal;
  199.     return(&vec);
  200. } // startup()
  201.  
  202. static int SAVEDS idofull(unsigned char *chunky,unsigned char *delta,int numscreen) {
  203.     return(mdofull(chunky,numscreen));
  204. } // idofull()
  205.  
  206. static int DummyGetOptionInt(char *name,int defval) { return(-1); }
  207. static void DummyAddOptionInt(char *name,int value) { return; }
  208. static char *DummyGetOptionStr(char *name,char *defval) { return(NULL); }
  209. static void DummyAddOptionStr(char *name,char *value) { return; }
  210.  
  211. static char *SAVEDS iinit(ULONG sm, ULONG ov, unsigned char *ld) {
  212.     c2p_sm=sm;    c2p_ov=ov;    c2p_ld=ld;
  213.     return(minit(sm,ov,ld));
  214. }
  215.  
  216. /* Locale functions, if required
  217.  */
  218. #ifdef C2P_LOCALIZE
  219.  
  220.  static char *c2p_ShowLocReq(long StringNum) {
  221.  static char nostr[]="***NOMSG";
  222.  static struct EasyStruct es_req={
  223.     sizeof(struct EasyStruct),
  224.     0,
  225.     "Locale error",
  226.     "Can't find string number %ld",
  227.     "Ok"
  228.  };
  229.  struct IntuitionBase *storeIntuiBase;
  230.     storeIntuiBase=IntuitionBase;
  231.     if(0L!=(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36))) {
  232.         EasyRequest(0L,&es_req,0L,(ULONG)StringNum);
  233.         CloseLibrary((struct Library *)IntuitionBase);
  234.         IntuitionBase=storeIntuiBase;
  235.     }
  236.     return(nostr);
  237.  } // c2p_ShowLocReq()
  238.  
  239.  static void c2p_ShowReq(char *t,char *b) {
  240.  static struct EasyStruct es_req={ sizeof(struct EasyStruct),0, 0L, 0L, "Ok" };
  241.  struct IntuitionBase *storeIntuiBase;
  242.      if(b==0L||t==0L) return;
  243.     storeIntuiBase=IntuitionBase;
  244.     if(0L!=(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36))) {
  245.         es_req.es_Title=t;
  246.         es_req.es_TextFormat=b;
  247.         EasyRequestArgs(0L,&es_req,0L,0L);
  248.         CloseLibrary((struct Library *)IntuitionBase);
  249.         IntuitionBase=storeIntuiBase;
  250.     }
  251.  } // c2p_ShowReq()
  252.  
  253.  void c2p_OpenCatalog(char *DefaultStrings[]) {
  254.     long i;
  255.     if(DefaultStrings==NULL) return;
  256.     for(i=0;DefaultStrings[i]!=NULL;i++);
  257.     c2p_DefaultStrings=DefaultStrings;
  258.     c2p_NumberOfMessages=i-1;
  259.     if(i==0) return;
  260.     if(!LocaleBase) LocaleBase=(struct LocaleBase *)OpenLibrary("locale.library",37);
  261.     if(LocaleBase!=0L&&c2p_Catalog==0L) {
  262.         c2p_Catalog=OpenCatalog(0L,(char *)C2P_CATALOGNAME,
  263.             OC_BuiltInLanguage, (unsigned long)C2P_BUILTINLANGUAGE,
  264.             OC_Version, 1L,
  265.             TAG_DONE,0L);
  266.     }
  267.  } // c2p_OpenCatalog()
  268.  
  269.  void c2p_CloseCatalog(void) {
  270.     if(LocaleBase!=0L) CloseCatalog(c2p_Catalog);
  271.     c2p_Catalog=0L;
  272.     if(LocaleBase) CloseLibrary((struct Library *)LocaleBase);
  273.     c2p_NumberOfMessages=0;
  274.  } // c2p_CloseCatalog()
  275.  
  276.  char *c2p_GetStr(long StringNum) {
  277.     char *rs=0L;
  278.     if(StringNum>=0&&StringNum<=c2p_NumberOfMessages&&LocaleBase!=0L) rs=GetCatalogStr(c2p_Catalog,StringNum+1,c2p_DefaultStrings[StringNum]);
  279.     else if(StringNum<=c2p_NumberOfMessages) rs=c2p_DefaultStrings[StringNum];
  280.     else rs=c2p_ShowLocReq(StringNum);
  281.     return(rs);
  282.  } // c2p_GetStr()
  283.  
  284.  INLINE void c2p_strncpy(char *to,char *fr,int l) {
  285.     while('\0'!=(*to++=*fr++)&&--l>=0);
  286.  } // c2p_strncpy()
  287.  
  288. #endif            // C2P_LOCALE
  289.  
  290. static int SAVEDS c2p_internal(int f) {
  291.     int r=0;
  292.     switch(f) {
  293. #ifdef C2P_LOCALIZE
  294.         case C2PIF_MODLOCALE : {
  295.             char *rs;
  296.             c2p_CloseCatalog();
  297.             mfree();
  298.             if(NULL!=(rs=minit(c2p_sm,c2p_ov,c2p_ld))) {
  299.                 c2p_ShowReq("Fatal error",rs);
  300.                 r=RET_ERROR;
  301.             }
  302.         }
  303.             break;
  304. #endif
  305.     }
  306.     return(r);
  307. } // c2p_internal()
  308.  
  309. #endif
  310.